package net.ak.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import net.ak.dao.PhoneDao;
import net.ak.model.Phone;
import net.ak.model.User;

@Repository
public class PhoneDaoImpl extends BaseDao<Phone> implements PhoneDao {
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Phone> listPhoneByUser(User user) {
		Session session 	= sessionFactory.getCurrentSession();
		Criteria criteria 	= session.createCriteria(Phone.class);
		criteria.add(Restrictions.eq("user_id", user.getId()));
		
		return criteria.list();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Phone> listAllPhones() {
		Session session 	= sessionFactory.getCurrentSession();
		Criteria criteria 	= session.createCriteria(Phone.class);
		
		return criteria.list();
	}

}
